package com.cash.app.ui.other.adapter

import android.annotation.SuppressLint
import android.net.Uri
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.cash.app.databinding.AcFeedbackSubmitItemBinding

class FeedbackPhotoAdapter : RecyclerView.Adapter<FeedbackPhotoAdapter.ViewHolder>() {

    private val photos = mutableListOf<Uri>()
    var onDeleteClick: ((Int) -> Unit)? = null

    @SuppressLint("NotifyDataSetChanged")
    fun updatePhotos(newPhotos: List<Uri>) {
        photos.clear()
        photos.addAll(newPhotos)
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding =
            AcFeedbackSubmitItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(photos[position])
    }

    override fun getItemCount(): Int = photos.size

    inner class ViewHolder(private val binding: AcFeedbackSubmitItemBinding) :
        RecyclerView.ViewHolder(binding.root) {
        fun bind(uri: Uri) {
            binding.ivPhoto.setImageURI(uri)
            binding.btnDelete.setOnClickListener {
                onDeleteClick?.invoke(adapterPosition)
            }
        }
    }
} 